package org.zn.mvcbase.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.zn.mvcbase.config.property.BootMvcProperty;
import org.zn.mvcbase.rest.RestEntity;
import org.zn.mvcbase.rest.RestEntityFactroy;
import org.zn.mvcbase.rest.RestGateway;

public class RestEntityController extends ResponseMessageController{
	
	@Autowired
	protected RestEntityFactroy restEntityFactroy;
	
	@Autowired
	private BootMvcProperty bootMvcProperty;
	
	
	protected String getServiceURL(String mskey) {
	
	RestGateway restGateway	=bootMvcProperty.getGateway();
	Map<String, String> mss= restGateway.getMicoService();
	Map<String, String> tss= restGateway.getTestService();
	
	String mode=restGateway.getMode();
	
	String url=null;
	
	if(mode.equals("debug")) {
		
		url=	tss.get(mskey);
		
	}
	else if(mode.equals("gateway")) {
		
		url=restGateway.getAddress()+"/"+mss.get(mskey);
		
	}
	
	
	return url;
	

	}
	

	
	protected RestEntity getRestEntity(HttpMethod method,String url) {
		
		return restEntityFactroy.getRestEntity(method, url);
		
	}
	
	protected RestEntity getRestEntity(HttpMethod method,String url,HttpEntity<?> requestEntity,Map<String, Object> variables) {
		
		RestEntity re=restEntityFactroy.getRestEntity(method, url);
		
		re.setRequestEntity(requestEntity);
		re.setVariables(variables);
		return re;
		
		
	}
	
}
